#!c:\python25\python.exe

from xml.sax import parse, SAXParseException, ContentHandler

class TagInfoHandler( ContentHandler ):
    def __init__( self, tagName ):
        ContentHandler.__init__( self )
        self.tagName = tagName
        self.depth = 0 # spaces to indent to show structure

    def startElement( self, name, attributes ):
        if name == self.tagName:
            print "\n%s<%s> started" % ( " " * self.depth, name )
            self.depth += 4
            print "%sAttributes:" % ( " " * self.depth )
            for attribute in attributes.getNames():
                print "%s%s = %s" % (" " * self.depth, attribute, attributes.getValue(attribute))

    def endElement( self, name ):
        if name == self.tagName:
            self.depth -= 4
            print "%s</%s> ended\n" % ( " " * self.depth, name )

    def characters(self, contents):
        pass
def main():
    tagName = raw_input( "Enter tag to search for: " )
    try:
        parse( "boxs.xml", TagInfoHandler(tagName) )
    except IOError, message:
        print "Error reading file:", message
    except SAXParseException, message:
        print "Error parsing file:", message

if __name__ == "__main__":
    main()
